package com.chen.yygh.common.utils;

import com.chen.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

//获取当前用户信息工具类
public class AuthContextHolder {
    //获取当前用户id
    public static Long getUserId(HttpServletRequest request){
        //从head中取token
        String token = request.getHeader("token");
        //使用jwt从token中取出userId
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取当前用户名称
    public static String getUserName(HttpServletRequest request){
        //从head中取token
        String token = request.getHeader("token");
        //使用jwt从token中取得名字
        String userName = JwtHelper.getUserName("token");
        return userName;
    }
}
